package com.milk;

import java.io.IOException;
import java.lang.reflect.Method;
import java.nio.charset.Charset;

import javax.annotation.Resource;
import javax.sql.DataSource;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.dubbo.annotation.EnableDubbo;
import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.CachingConfigurerSupport;
import org.springframework.cache.interceptor.KeyGenerator;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.context.annotation.Primary;
import org.springframework.data.redis.cache.RedisCacheManager;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.transaction.annotation.TransactionManagementConfigurer;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RestController;

import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.PropertyAccessor;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.lorne.tx.compensate.repository.CompensateDataSource;
import com.lorne.tx.db.LCNDataSourceProxy;

@SpringBootApplication
@EnableAspectJAutoProxy(exposeProxy=true,proxyTargetClass=true)
@EnableDubbo
@EnableTransactionManagement(order = 2)
@MapperScan(basePackages = "com.milk.service.**.dao")
@ComponentScan(basePackages = {"com.milk","com.lorne"})
public class StartApplication{
	
	static ConfigurableApplicationContext context;
	
	public static void main(String[] args) throws IOException{
		
		System.setProperty("dubbo.service.shutdown.wait", "30000");//这里定义的是应用关闭后最大延缓关闭的时间（超过这个时段的运行线程依旧会被强制关闭，默认10秒）
		context = new SpringApplicationBuilder()
                .sources(StartApplication.class)
                .web(false)
                .run(args);
		
		System.in.read();
	}
}
